#include "stdafx.h"
#include "fuTreeCtrl.h"

fuTreeCtrl::fuTreeCtrl(void)
: wxTreeCtrl()
{
}

fuTreeCtrl::fuTreeCtrl(wxWindow *         parent,
                       wxWindowID         id /*= wxID_ANY*/,
                       const wxPoint&     pos /*= wxDefaultPosition*/,
                       const wxSize&      size /*= wxDefaultSize*/, 
                       long               style /*= wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT*/,
                       const wxValidator& validator /*= wxDefaultValidator*/, 
                       const wxString&    name /*= wxTreeCtrlNameStr*/ ) :
wxTreeCtrl(parent, id, pos, size, style, validator, name)
{
}

fuTreeCtrl::~fuTreeCtrl(void)
{
}

wxTreeItemId fuTreeCtrl::GetNext( const wxTreeItemId& item, bool fulltree ) const
{
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));

    // if there are any children, return first child
    if( fulltree || IsExpanded(item) ) {
        wxTreeItemIdValue cookie;
        wxTreeItemId child = GetFirstChild(item,cookie);
        if( child.IsOk() )
            return child;
    }

    // get sibling of this item or of the ancestors instead
    wxTreeItemId next;
    wxTreeItemId parent = item;
    do {
        next = GetNextSibling (parent);
        parent = GetItemParent (parent);
    } while (!next.IsOk() && parent.IsOk());
    return next;
}

wxTreeItemId fuTreeCtrl::GetPrev( const wxTreeItemId& item, bool fulltree ) const
{
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));

    // if there are any children, return last child
    if( fulltree || IsExpanded(item) ) {
        wxTreeItemId child = GetLastChild(item);
        if( child.IsOk() )
            return child;
    }

    // get sibling of this item or of the ancestors instead
    wxTreeItemId next;
    wxTreeItemId parent = item;
    do {
        next = GetPrevSibling (parent);
        parent = GetItemParent (parent);
    } while (!next.IsOk() && parent.IsOk());
    return next;
}
